<template>
  <div class="payment">
    <headerNav title="支付方式"/>
    <div class="pay">
      <van-radio-group v-model="radio">
        <van-cell-group>
          <div class="pay_box" v-for="(item,index) in list" :key="index" @click="changeRadio(item,index)">
            <img class="Img" v-if="item.productNo=='ALIPAY_WAP_WEB'" src="../../assets/images/zfb.png">
            <img class="Img" v-if="item.productNo=='WEICHAT_H5'" src="../../assets/images/wx.png">
            <van-cell :title="item.productName" clickable> 
              <van-radio slot="right-icon" :name="index" />
            </van-cell>
          </div> 
        </van-cell-group>
      </van-radio-group>
      <p class="button" @click="parSubmit">支付</p>
    </div>
  </div>
</template>
<script>
import { findPayWayList,startPay } from "../../api/page.js";

export default {
  name: "payment",
  data: function() {
    return {
      radio: 0,
      list:[],
      payWay:"",
    };
  },
  created: function() {
    findPayWayList().then(res=>{
      if(res.retCode=="200"){
        this.list = res.data
        this.payWay = this.list[0].productNo
      }
    })
  },
  methods: {
    changeRadio(item,index){
      this.payWay = item.productNo
      this.radio = index
    },
    parSubmit(){
      startPay({
        orderNo:this.$route.query.orderNo,
        payWay:this.payWay,
        webSource:"H5_WEB"
      }).then(res=>{
        let url = ""
        if (process.env.VUE_APP_CURRENTMODE == 'test') {
          url='http://106.15.237.241:8081/'; //测试
        }else if(process.env.VUE_APP_CURRENTMODE == 'production'){
          url = 'https://www.yixuanshow.top/'; //生产
        }else{
          url = 'http://106.15.237.241:8081/'; //本地
        }
        window.location.href = url+"app/user/pay/startPay?orderNo="+this.$route.query.orderNo+"&payWay="+this.payWay+"&webSource=H5_WEB" 
      })
    }
  }
};
</script>
<style scoped lang="less">
  .pay{
    padding-top: .56rem;
  }
  .van-cell{
    width: 88%;
  }
  .Img{
    width: .32rem;
    height: .32rem;
  }
  .pay_box{
    display: flex;
    justify-content: flex-start;
    padding:.1rem 0 .1rem .15rem;
    align-items: center;
  }
  .button{
    height: .5rem;
    width: 80%;
    background:#F93835;
    font-size: .16rem;
    color: #fff;
    line-height: .5rem;
    text-align: center;
    margin:0 auto;
    margin-top: 1rem;
    border-radius: .3rem;
  }
</style>
